﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BOHVote.BLL;
using System.Data;

namespace BOH.DataManagement
{
    public partial class GovernAllowApply : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindingGovern();
            }
        }

        public void BindingGovern()
        {
            DataSet Governdst = UnitClass.getGovern("", "");
            GovernAllowApplyList.DataSource = Governdst;
            GovernAllowApplyList.DataBind();
        }

        protected void GovernAllowApplyList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToLower() == "save")
            {
                GridViewRow gvr = GovernAllowApplyList.Rows[Convert.ToInt32(e.CommandArgument)];
                string hidGovern = ((HiddenField)gvr.FindControl("hidGovern")).Value;
                string IsOpen = ((DropDownList)gvr.FindControl("drpIsOpen")).SelectedValue;
                UnitClass.UpdateAllowApplyofGovern(hidGovern, IsOpen);
                BindingGovern();
            }
        }

        protected void butOpenAll_Click(object sender, EventArgs e)
        {
            UnitClass.UpdateAllowApplyofGovern("", "Y");
            BindingGovern();
        }

        protected void butCloseAll_Click(object sender, EventArgs e)
        {
            UnitClass.UpdateAllowApplyofGovern("", "N");
            BindingGovern();
        }

        protected void GovernAllowApplyList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string hidAllowApply = ((HiddenField)e.Row.FindControl("hidAllowApply")).Value;
                DropDownList drIsOpen = ((DropDownList)e.Row.FindControl("drpIsOpen"));
                if (drIsOpen != null)
                {
                    drIsOpen.SelectedValue = hidAllowApply;
                }
            }
        }
    }
}
